﻿using Jinjia.Approve.API.Controllers.Base;
using Jinjia.Approve.Entity.Entity.JJFlow;
using Jinjia.Approve.IRepository;
using Jinjia.Approve.IService;
using Jinjia.Approve.Model;
using Jinjia.Approve.Model.Input.JJFlow;
using Jinjia.Approve.Model.VM.JJFlow;
using Jinjia.Approve.Service;
using Jinjia.Core.BaseInfrastructure.ApiResultCodeComponent;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar.Extensions;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

namespace Jinjia.Approve.API.Controllers
{
    /// <summary>
    /// 审批流模板远程接口维护
    ///</summary>
    [AllowAnonymous]
    public class JJFlowTemplateRemoteInterfaceController : BaseController
    {
        private readonly IJJFlowTemplateRemoteInterfaceService _service;

        public JJFlowTemplateRemoteInterfaceController(IJJFlowTemplateRemoteInterfaceService service)
        {
            _service = service;
        }

        /// <summary>
        /// 下拉列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetDropDownListAsync()
        {
            return Success(await _service.GetDropDownListAsync());
        }

        /// <summary>
        /// 远程接口调试
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> GetRemoteInterfaceAsync(RemoteInterfaceInput<object> input)
        {
            return Success(await _service.GetRemoteInterfaceAsync<object, object>(input));
        }

        /// <summary>
        /// Get示例
        /// </summary>
        /// <param name="biz_order_id"></param>
        /// <param name="start_user"></param>
        /// <param name="depart_id"></param>
        /// <param name="functionCode"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult TestGetAsync(string biz_order_id, int start_user, string depart_id, string functionCode, bool content)
        {
            if (content.ObjToBool())
            {
                return Success(true);
            }
            else
            {
                return Success(new List<int> { 1, 2, 3, 10 });
            }
        }

        /// <summary>
        /// Post示例,尽可能使用Post,容易扩展
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult TestPostAsync(RemoteInterfaceInput<object> input)
        {
            if (input.Content.ObjToBool())
            {
                return Success(true);
            }
            else
            {
                return Success(new List<int> { 1, 2, 3, 10 });
            }
        }
    }
}